<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 核心是通过object.create实现把子类自身的prototype赋值为父类的prototype
      // 缺点：子类自身的prototype有其他属性的话会被覆盖
      function Parent() {
        this.say = function () {
          console.log(this.name);
        };
      }
      Parent.prototype.test = 1;
      function Child() {
        Parent.call(this);
        this.name = "child";
      }
      Child.prototype = Object.create(Parent.prototype);
      let p = new Child();
      console.log(p);
    </script>
  </body>
</html>
